import random
import time
from unsplash_spider_image.produce_spider_foreign_image import UnsplashImageSpiderProduce
from unsplash_spider_image.consume_spider_foreign_image import UnsplashImageSpiderConsume

#
#
# random_time = random.randint(1, 3)
# page = 1
# query = 'finance'
# page_size = 3
# produce = UnsplashImageSpiderProduce(query)
# consume = UnsplashImageSpiderConsume(query)
# xhr_json = produce.xhr_get_method(page, page_size)
# total_pages = xhr_json['total_pages']
# print('total_pages', total_pages)
# #for page in range(1, total_pages+1):
# for pageindex in range(1, 2):
#     page_json = produce.xhr_get_method(pageindex, page_size)
#     produce.parse_html(page_json)
#     time.sleep(random_time)

#
# page = 1
# query = 'finance'
# page_size = 3
# produce = UnsplashImageSpiderProduce()
# xhr_json = produce.xhr_get_method(page, query, page_size)
# total_pages = xhr_json['total_pages']
# print('total_pages', total_pages)
# #for page in range(1, total_pages+1):
# for pageindex in range(1, 2):
#     page_json = produce.xhr_get_method(pageindex, query, page_size)
#     oss_urls, mysql_data = produce.parse_html(page_json)
#     print('oss_urls', oss_urls)
#     print('mysql_data', mysql_data)
# #     for oss_url in oss_urls:
# #         print('oss_urls', oss_urls)
# #         try:
# #             unsplash.oss_url_image(oss_url)
# #         except Exception as e:
# #             print(e)
# # print('下载完毕')
